package com.vidyu.businesslayer.businessentities;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: eyalsa
 * Date: 3/31/13
 * Time: 7:38 PM
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "employers")
@NamedQueries({
        @NamedQuery(
                name = "getEmployerByEmail",
                query = "FROM com.vidyu.businesslayer.businessentities.Employer as employer WHERE employer.email = ?"
        ),
        @NamedQuery(
                name = "getEmployerByEmailAndPassword",
                query = "FROM com.vidyu.businesslayer.businessentities.Employer as employer WHERE employer.email = ? AND employer.password = ?"
        )


})
public class Employer extends User implements Serializable {
    private static final long serialVersionUID = 3277073386711729397L;

    private String companyName;
    private String companyDesc;
    private String companyWebSite;

    public Employer (){}


    public Employer(String name, String email, String password, String address, String country,
                    String companyName, String companyDesc, String companyWebSite) {
        super(name, email, password, address, country);
        this.companyName = companyName;
        this.companyDesc = companyDesc;
        this.companyWebSite = companyWebSite;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getCompanyDesc() {
        return companyDesc;
    }

    public void setCompanyDesc(String companyDesc) {
        this.companyDesc = companyDesc;
    }

    public String getCompanyWebSite() {
        return companyWebSite;
    }

    public void setCompanyWebSite(String companyWebSite) {
        this.companyWebSite = companyWebSite;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "employer_to_projects_connection", joinColumns = @JoinColumn(name = "employer_id"), inverseJoinColumns = @JoinColumn(name = "project_id"))
    public Set<Project> getProjectSet() {
        return projectSet;
    }

    public void setProjectSet(Set<Project> projectSet) {
        this.projectSet = projectSet;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Employer employer = (Employer) o;

        if (companyDesc != null ? !companyDesc.equals(employer.companyDesc) : employer.companyDesc != null)
            return false;
        if (companyName != null ? !companyName.equals(employer.companyName) : employer.companyName != null)
            return false;
        if (companyWebSite != null ? !companyWebSite.equals(employer.companyWebSite) : employer.companyWebSite != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = companyName != null ? companyName.hashCode() : 0;
        result = 31 * result + (companyDesc != null ? companyDesc.hashCode() : 0);
        result = 31 * result + (companyWebSite != null ? companyWebSite.hashCode() : 0);
        return result;
    }
}
